package linc.spring.demo;

import linc.spring.demo.bean.User;
import org.junit.Test;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 * @author yqlin
 * @date 2021/9/7 00:32
 * @description
 */
public class SpringFactoryTest {
    /**
     * BeanFactory会负责创建Bean，并且提供获取Bean的API。
     * 而ApplicationContext是BeanFactory的一种
     */
    @Test
    public void testBeanFactory() {

    }

    @Test
    public void testDefaultListableBeanFactory() {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(User.class).getBeanDefinition();
        beanFactory.registerBeanDefinition("user", beanDefinition);
        System.out.println(beanFactory.getBean("user"));
    }
}
